/*
  学习目标：ref获取dom元素-input
  1. 获取dom元素
  2. 获取组件实例
*/

import React, { Component } from 'react';

export default class App extends Component {
  // 1.
  childRef = React.createRef();
  handleClick = () => {
    // 3.
    this.childRef.current.handleAlert();
  };

  render() {
    return (
      <div>
        <button onClick={this.handleClick}>点我获取Child组件</button>

        <Child
          // 2.
          ref={this.childRef}
        ></Child>
      </div>
    );
  }
}

class Child extends React.Component {
  state = {
    count: 100,
  };
  handleAlert() {
    alert('我是一个大baby');
  }
  render() {
    return <div></div>;
  }
}
